package team.future.joke.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import team.future.joke.constant.StatusConstants;
import team.future.joke.dao.BaseMongoDao;
import team.future.joke.entity.JokeLike;
import team.future.joke.entity.JokeLog;
import team.future.joke.entity.JokeStore;
import team.future.joke.service.JokeLikeService;
import team.future.joke.service.JokeLogService;
import team.future.joke.service.JokeService;
import team.future.joke.service.JokeStoreService;

/**
 * Title: JokeLogServiceImpl.java<br>
 * Description: <br>
 * Copyright (c) 未来工作室版权所有 2015    <br>
 * Create DateTime: 2015年9月13日 上午10:02:41 <br>
 * @author futurezhu
 */
@Service("jokeLogService")
public class JokeLogServiceImpl implements JokeLogService {

    @Autowired
    private BaseMongoDao<JokeLog> jokeLogDao;
    @Autowired
    private JokeService jokeService;
	@Autowired
	private JokeStoreService jokeStoreService;
	@Autowired
	private JokeLikeService jokeLikeService;
    @Override
	public void doInsertLog(JokeLog jokeLog) {
		String jokeId = jokeLog.getJokeId();
		switch (jokeLog.getOpType()) {
		case StatusConstants.USER_OP_TYPES_LIKES:
			JokeLike like = new JokeLike();
			like.setJokeId(jokeId);
			like.setUid(jokeLog.getUid());
			jokeLikeService.insertLike(like);
			jokeService.updateJokeLikesAdd(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_NOT_LIKES:
			jokeLikeService.deleteLike(jokeId, jokeLog.getUid());
			jokeService.updateJokeLikesMius(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_STORE:
			JokeStore store = new JokeStore();
			store.setJokeId(jokeId);
			store.setUid(jokeLog.getUid());
			jokeStoreService.insertStore(store);
			jokeService.updateJokeCollectAdd(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_NOT_STORE:
			jokeStoreService.deleteStore(jokeId, jokeLog.getUid());
			jokeService.updateJokeCollectMius(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_SHARE_SINAWEIBO:
			jokeService.updateJokeSinaWeiboAdd(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_SHARE_WEIXINPY:
			jokeService.updateJokeWeixinpyAdd(jokeId);
			break;
		case StatusConstants.USER_OP_TYPES_SHARE_WEIXINPYQ:
			jokeService.updateJokeWeixinpyqAdd(jokeId);
			break;
		default:
			break;
		}
		jokeLog.setTime(new Date());
        jokeLogDao.insertObject(jokeLog);
    }


}
